<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>tool_apidoc工具</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="data/layui/css/layui.css"  media="all">
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>


<div id="top_page"></div>


<form class="layui-form" method="post" onSubmit="return test_form();">
  <div class="layui-tab">
    <ul class="layui-tab-title">
      <li class="layui-this">postman_json转apidoc</li>
      <li>postman_kv转apidoc</li>
    </ul>
    <div class="layui-tab-content">
      <div class="layui-tab-item layui-show" data-method="postman_json2apidoc">
        <div class="layui-form-item layui-form-text">
          <label class="layui-form-label">输入json</label>
          <div class="layui-input-block">
            <textarea name="input_data" placeholder="postman复制的json" class="layui-textarea"></textarea>
          </div>
        </div>
        <div class="layui-form-item layui-form-text">
          <label class="layui-form-label">输出json</label>
          <div class="layui-input-block">
            <textarea name="out_data" placeholder="apidoc需要的json格式" class="layui-textarea" readonly rows=20></textarea>
          </div>
        </div>
      </div>

      <div class="layui-tab-item" data-method="postman_kv2apidoc">
          <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">输入kv</label>
            <div class="layui-input-block">
              <textarea name="input_data" placeholder="postman复制的kv" class="layui-textarea"></textarea>
            </div>
          </div>
          <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">输出json</label>
            <div class="layui-input-block">
              <textarea name="out_data" placeholder="apidoc需要的json格式" class="layui-textarea" readonly rows=20></textarea>
            </div>
          </div>
      </div>

    </div>
  </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button  class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>

</form>


<script src="data/layui/layui.all.js"></script>
<script src="data/jquery-2.0.2.min.js"></script>
<script type="text/javascript" language="javascript">
  // 禁止load使用缓存页面
  $.ajaxSetup ({
    cache: false //close AJAX cache
  });

  //引入公共头部
  $("#top_page").load("top.html");

</script>
<script>

  $(function(){
    //注意：导航 依赖 element 模块，否则无法进行功能性操作
    layui.use('element', function(){
      var element = layui.element;

      //…
    });
  })

  function test_form(){
    var selector = $('.layui-show');
    var input_data = selector.find('textarea[name="input_data"]').val();
    //postman_json2apidoc
    //postman_kv2apidoc
    var method = selector.data('method');

    $.get('http://tool.zhaizhaiplan.com/act/index.php?act='+method, {input_data:input_data}, function(res){

      console.log(res.data);
      console.log(res);

      if(res.status != 0){
        selector.find('textarea[name="out_data"]').attr('style', '');
        selector.find('textarea[name="out_data"]').val(res.data);
      }else{
        selector.find('textarea[name="out_data"]').attr('style', 'color:red;text-align:left');
        selector.find('textarea[name="out_data"]').val(res.msg);
      }

    },'JSON');

    return false;
  }

</script>


</body>
</html>

